package com.service.impl;

import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.dao.StudentDao;
import com.entity.Student;
import com.service.StudentService;

@Service
@EnableTransactionManagement
public class StudentServiceImpl implements StudentService {
	@Autowired
	private StudentDao studentDao;

	public StudentDao getStudentDao() {
		return studentDao;
	}

	public void setStudentDao(StudentDao studentDao) {
		this.studentDao = studentDao;
	}

	public List<Student> getAllStudent() throws SQLException, ClassNotFoundException {
		return studentDao.getAllStudent();
	}
	public List<Student> getStudentByName(String name) throws SQLException, ClassNotFoundException{
		return studentDao.getStudentByName(name);
	}
	@Transactional(value="transactionManager",propagation = Propagation.REQUIRED,rollbackFor={ArithmeticException.class})
	public boolean addStudent(Student student) throws IllegalArgumentException, IllegalAccessException, SQLException,ArithmeticException {
		boolean i  = studentDao.addStudent(student) >0?true:false;
		int j = 1/0;
		Student student2 = new Student(String.valueOf(Integer.parseInt(student.getSno())+1),student.getName());
		boolean t  = studentDao.addStudent(student2) >0?true:false;
		return false;
	}
	@Transactional(value="transactionManager",propagation = Propagation.REQUIRED,rollbackFor={ArithmeticException.class})
	public boolean updateStudent(Student student) {
		int j = 1/0;
		return false;
	}

}
